﻿using System.Windows.Forms;

namespace Outlook.WorkItems.Extension.Controls
{
    public partial class SelectQueryBox : Form
    {
        public SelectQueryBox()
        {
            InitializeComponent();
        }

        public void InitializeTree()
        {
            teamTreeView1.treeView1.AfterSelect += treeView1_AfterSelect;
            teamTreeView1.InitTreeView();
        }

        public string TeamServerUri
        {
            get
            {
                QueryNode node = teamTreeView1.treeView1.SelectedNode as QueryNode;
                if (node != null)
                    return node.TeamServerUri;
                return null;
            }
        }
        public Microsoft.TeamFoundation.WorkItemTracking.Client.QueryDefinition SelectedQuery
        {
            get
            {
                QueryNode node = teamTreeView1.treeView1.SelectedNode as QueryNode;
                if (node != null)
                    return node.TeamQuery;

                return null;
            }
        }

        private void treeView1_AfterSelect(object sender, TreeViewEventArgs e)
        {
            btnOk.Enabled = e.Node is QueryNode;
        }

        private void SelectQueryBox_Load(object sender, System.EventArgs e)
        {
            InitializeTree();
        }
    }
}
